//
//  HNQueue.m
//  HeroNuts
//
//  Created by Gelford on 11-4-14.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "HNQueue.h"


@implementation HNQueue

- (void) dealloc
{
  [super dealloc];
}

- (id) init
{
  tail = -1;
  head = -1;
  count = 0;
  for (int i = 0; i < 400; i++) {
    queue[i] = -1;
  }
  return self;
}

- (void) push:(int)pushElement
{
  count ++;
  if(head == -1){
    head = 0;
  }
  if (tail == 400) {
    tail = 0;
  }else{
    tail++;
  }
  queue[tail] = pushElement;
}

- (int)front
{
  if (head == -1) {
    return -1;
  }
  return queue[head];
}

- (BOOL)empty
{
  if (count == 0) {
    return YES;
  }
  else{
    return NO;
  }
}

- (void)pop
{
  count --;
  queue[head] = -1;
  if (head == 400) {
    head = 0;
  }else{
    head ++;
  }
}


@end
